#!/bin/bash

# 检查输入参数是否足够
if [[ $# -lt 2 ]]; then
    echo "错误：请输入算法。"
    echo "用法：$0 <cc> <number>"
    exit 1
fi


# 获取输入的参数
cc=$1
number=$2

for wl in {10..90..10}; do
    # # 回显即将执行的命令
    # echo "即将执行以下命令："
    # for i in {01..09}; do
    #     echo "nohup ./waf --run \"scratch/third input/config_${cc}_${wl}.txt ${wl}_${number}_$i $(echo "scale=1; $i / 10" | bc)\" > log/run_${cc}_${wl}_${number}_$i.log 2>&1 &"
    # done
    # for i in {001..009}; do
    #     echo "nohup ./waf --run \"scratch/third input/config_${cc}_${wl}.txt ${wl}_${number}_$i $(echo "scale=1; $i * 0.01" | bc)\" > log/run_${cc}_${wl}_${number}_$i.log 2>&1  &"
    # done
    # echo "nohup ./waf --run \"scratch/third input/config_${cc}_${wl}.txt ${wl}_${number}_ori 100\" > log/run_${cc}_${wl}_${number}_ori.log 2>&1  &"         ## using 

    # # 确认是否执行命令
    # read -p "确认执行${wl}%负载的实验嘛? (y/n): " confirm
    # if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
    #     echo "取消执行。"
    #     exit 0
    # fi

    # 执行命令
    echo "Building"
    ./waf build > /dev/null 2>&1
    sleep 2
    echo "Building Finished."
    for i in {01..09}; do
        echo "nohup ./waf --run "scratch/third input/config_${cc}_${wl}.txt ${wl}_${number}_$i $(echo "scale=1; $i / 10" | bc)" > log/run_${cc}_${wl}_${number}_$i.log 2>&1 &"
        nohup ./waf --run "scratch/third input/config_${cc}_${wl}.txt ${wl}_${number}_$i $(echo "scale=1; $i / 10" | bc)" > log/run_${cc}_${wl}_${number}_$i.log 2>&1 &
        sleep 1.5
        tail -n 1 log/run_${cc}_${wl}_${number}_$i.log
    done
    for i in {001..009}; do
        echo "nohup ./waf --run "scratch/third input/config_${cc}_${wl}.txt ${wl}_${number}_$i $(echo "scale=1; $i * 0.01" | bc)" > log/run_${cc}_${wl}_${number}_$i.log 2>&1 &"
        nohup ./waf --run "scratch/third input/config_${cc}_${wl}.txt ${wl}_${number}_$i $(echo "scale=1; $i * 0.01" | bc)" > log/run_${cc}_${wl}_${number}_$i.log 2>&1 &
        sleep 1.5
        tail -n 1 log/run_${cc}_${wl}_${number}_$i.log
    done

    echo "nohup ./waf --run \"scratch/third input/config_${cc}_${wl}.txt ${wl}_${number}_ori 100\" > log/run_${cc}_${wl}_${number}_ori.log 2>&1  &"
    nohup ./waf --run "scratch/third input/config_${cc}_${wl}.txt ${wl}_${number}_ori 100" > log/run_${cc}_${wl}_${number}_ori.log 2>&1  &
    sleep 1.5
    tail -n 1 log/run_${cc}_${wl}_${number}_ori.log
    # 提示执行完成
    echo "命令已执行完毕"

done
